/**
 * 管理初始化
 */
var FoodsIngredient = {
    id: "FoodsIngredientTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
FoodsIngredient.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'foodId', visible: true, align: 'center', valign: 'middle'},
            {title: '热量', field: 'calory', visible: true, align: 'center', valign: 'middle'},
            {title: '碳水化合物', field: 'carbohydrate', visible: true, align: 'center', valign: 'middle'},
            {title: '胆固醇', field: 'cholesterol', visible: true, align: 'center', valign: 'middle'},
            {title: '铜', field: 'copper', visible: true, align: 'center', valign: 'middle'},
            {title: '脂肪', field: 'fat', visible: true, align: 'center', valign: 'middle'},
            {title: '膳食纤维', field: 'fiberDietary', visible: true, align: 'center', valign: 'middle'},
            {title: '碘', field: 'iodine', visible: true, align: 'center', valign: 'middle'},
            {title: '铁', field: 'iron', visible: true, align: 'center', valign: 'middle'},
            {title: '钾', field: 'kalium', visible: true, align: 'center', valign: 'middle'},
            {title: '核黄素（维生素b2）', field: 'lactoflavin', visible: true, align: 'center', valign: 'middle'},
            {title: '镁', field: 'magnesium', visible: true, align: 'center', valign: 'middle'},
            {title: '锰', field: 'manganese', visible: true, align: 'center', valign: 'middle'},
            {title: '钠', field: 'natrium', visible: true, align: 'center', valign: 'middle'},
            {title: '烟酸', field: 'niacin', visible: true, align: 'center', valign: 'middle'},
            {title: '蛋白质', field: 'protein', visible: true, align: 'center', valign: 'middle'},
            {title: '硒', field: 'selenium', visible: true, align: 'center', valign: 'middle'},
            {title: '维生素b1', field: 'thiamine', visible: true, align: 'center', valign: 'middle'},
            {title: '维生素a', field: 'vitaminA', visible: true, align: 'center', valign: 'middle'},
            {title: '维生素b', field: 'vitaminB', visible: true, align: 'center', valign: 'middle'},
            {title: '维生素c', field: 'vitaminC', visible: true, align: 'center', valign: 'middle'},
            {title: '维生素e', field: 'vitaminE', visible: true, align: 'center', valign: 'middle'},
            {title: '锌', field: 'zinc', visible: true, align: 'center', valign: 'middle'},
            {title: '钙', field: 'calcium', visible: true, align: 'center', valign: 'middle'},
            {title: '磷', field: 'phosphor', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'createBy', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'updateBy', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'updateDate', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'delFlag', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'remarks', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
FoodsIngredient.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        FoodsIngredient.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
FoodsIngredient.openAddFoodsIngredient = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/foodsIngredient/foodsIngredient_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
FoodsIngredient.openFoodsIngredientDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/foodsIngredient/foodsIngredient_update/' + FoodsIngredient.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
FoodsIngredient.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/foodsIngredient/delete", function (data) {
            Feng.success("删除成功!");
            FoodsIngredient.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("foodsIngredientId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
FoodsIngredient.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    FoodsIngredient.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = FoodsIngredient.initColumn();
    var table = new BSTable(FoodsIngredient.id, "/foodsIngredient/list", defaultColunms);
    table.setPaginationType("client");
    FoodsIngredient.table = table.init();
});
